

/*
    Copyright 2011,2012 Calum Stuart Cookson.

    This file is part of Bio Mongoose.

    Bio Mongoose is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Bio Mongoose is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Bio Mongoose.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef PROGRAM_ARGS_H_INCLUDED
#define PROGRAM_ARGS_H_INCLUDED

#include <vector>
#include <string>
#include <map>

class program_args
{
    public:
    void parse(int argc, char *argv[], char switch_char = '-')
    {

        for(int i = 0 ; i < argc ; i++)
        {
            std::string this_arg = argv[i];

            if(this_arg[0]==switch_char)
                add_switch(this_arg);
            else
                arguments.push_back(this_arg);
        }
    }
    int number_of_args() const
    {
        return arguments.size();
    }
    std::string get_argument(int arg) const
    {
        return arguments.at(arg);
    }
    std::string get_switch(std::string _switch) const
    {
        return switches.at(_switch);
    }
    bool has_switch(const std::string _switch) const
    {
        return switches.find(_switch) != switches.end();
    }
    std::string get_exe_name() const
    {
        return exe_name;
    }
    private:
    void add_switch(std::string this_switch)
    {
        std::vector<std::string> fields = utility::split(this_switch, ":");
        if(fields.size() >= 2)
            switches[fields[0]] = fields[1];
        else if(fields.size() == 1)
            switches[fields[0]] = "";
    }
    std::map<std::string, std::string> switches;
    std::vector<std::string> arguments;
    std::string exe_name;
};

#endif // PROGRAM_ARGS_H_INCLUDED
